package cn.yhjz.platform.system.service.impl;

import cn.yhjz.common.Pager;
import cn.yhjz.platform.system.entity.SysMenu;
import cn.yhjz.platform.system.vo.SysMenuVo;
import cn.yhjz.platform.system.mapper.SysMenuMapper;
import cn.yhjz.platform.system.service.ISysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(rollbackFor = {Exception.class})
public class SysMenuServiceImpl implements ISysMenuService {

    @Autowired
    private SysMenuMapper sysMenuMapper;


    @Override
    public Pager getPage(Long currentPage, Long pageSize, SysMenu sysMenu) {
        Pager pager = new Pager();
        Long count = sysMenuMapper.getPageCount(sysMenu);
        Long pageOffset = (currentPage - 1) * pageSize;
        List<SysMenuVo> records = sysMenuMapper.getPage(pageOffset, pageSize, sysMenu);
        pager.setRows(records);
        pager.setCurrentPage(currentPage);
        pager.setPageSize(pageSize);
        pager.setTotalPageCount(count);
        return pager;
    }

    @Override
    public SysMenu insert(SysMenu sysMenu) {
        int res = sysMenuMapper.insert(sysMenu);
        if(res > 0){
            return sysMenu;
        }else{
            return null;
        }
    }

    @Override
    public List<SysMenuVo> select(SysMenu sysMenu) {
        return sysMenuMapper.select(sysMenu);
    }
    @Override
    public List<SysMenuVo> selectMenu(SysMenu sysMenu) {
        return sysMenuMapper.selectMenu(sysMenu);
    }
    @Override
    public SysMenuVo selectById(Long id) {
        return sysMenuMapper.selectById(id);
    }

    @Override
    public int deleteById(Long id) {
        return sysMenuMapper.deleteById(id);
    }

    @Override
    public int updateByIdWithNull(SysMenu sysMenu) {
        return sysMenuMapper.updateByIdWithNull(sysMenu);
    }

    @Override
    public int updateById(SysMenu sysMenu) {
        return sysMenuMapper.updateById(sysMenu);
    }

    @Override
    public int update(SysMenu entity, SysMenu param) {
        return sysMenuMapper.update(entity, param);
    }

    @Override
    public int updateWithNull(SysMenu entity, SysMenu param) {
        return sysMenuMapper.updateWithNull(entity, param);
    }
}
